<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title th:text="${creator.name} + ' 的作品 - 电影网站'"></title>
    <link rel="stylesheet" href="/css/bootstrap.min.css">
    <link rel="stylesheet" href="/css/style.css">
</head>
<body>
<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
    <div class="container">
        <a class="navbar-brand" href="/">电影网站</a>
        <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav">
            <span class="navbar-toggler-icon"></span>
        </button>
        <div class="collapse navbar-collapse" id="navbarNav">
            <ul class="navbar-nav me-auto">
                <li class="nav-item">
                    <a class="nav-link" href="/movie/ranking/weekly">周榜</a>
                </li>
                <li class="nav-item">
                    <a class="nav-link" href="/movie/ranking/monthly">月榜</a>
                </li>
                <li class="nav-item">
                    <a class="nav-link" href="/movie/ranking/all">总榜</a>
                </li>
                <li class="nav-item">
                    <a class="nav-link" href="/movie/ranking/rating">评分榜</a>
                </li>
            </ul>
            <ul class="navbar-nav">
                <li class="nav-item" th:if="${session.user == null}">
                    <a class="nav-link" href="/login">登录</a>
                </li>
                <li class="nav-item dropdown" th:if="${session.user != null}">
                    <a class="nav-link dropdown-toggle" href="#" data-bs-toggle="dropdown">
                        <span th:text="${session.user.username}"></span>
                        <span class="badge bg-warning" th:if="${session.user.isVip}">VIP</span>
                    </a>
                    <ul class="dropdown-menu">
                        <li><a class="dropdown-item" href="/order/vip" th:if="${!session.user.isVip}">开通VIP</a></li>
                        <li><a class="dropdown-item" href="/admin" th:if="${session.user.isAdmin}">后台管理</a></li>
                        <li><hr class="dropdown-divider"></li>
                        <li><a class="dropdown-item" href="/logout">退出登录</a></li>
                    </ul>
                </li>
            </ul>
        </div>
    </div>
</nav>

<div class="container mt-4">
    <div class="row">
        <div class="col-md-8">
            <div class="card mb-4">
                <div class="card-body">
                    <div class="d-flex align-items-center mb-4">
                        <img th:src="${creator.avatar != null ? creator.avatar : '/image/default-avatar.png'}" alt="主创照片" 
                             style="width: 100px; height: 100px; object-fit: cover; border-radius: 50%;">
                        <div class="ms-4">
                            <h3 class="mb-2" th:text="${creator.name}"></h3>
                            <p class="text-muted mb-2" th:text="${type == 'director' ? '导演' : '演员'}"></p>
                            <p class="mb-0" th:text="${creator.biography}"></p>
                        </div>
                    </div>
                </div>
            </div>

            <div class="card">
                <div class="card-header">
                    <h5 class="card-title mb-0" th:text="${creator.name} + ' 的作品'"></h5>
                </div>
                <div class="card-body">
                    <div class="row row-cols-2 row-cols-md-4 g-4">
                        <div class="col" th:each="movie : ${movies}">
                            <div class="card h-100">
                                <img th:src="${movie.coverUrl}" class="card-img-top" alt="电影封面">
                                <div class="card-body">
                                    <h6 class="card-title">
                                        <a th:href="@{'/movie/' + ${movie.id}}" class="text-decoration-none" th:text="${movie.name}"></a>
                                        <span class="badge bg-warning ms-1" th:if="${movie.isVip}">VIP</span>
                                    </h6>
                                    <p class="card-text small">
                                        <span th:each="category : ${movie.categories}" class="badge bg-primary me-2" th:text="${category}"></span>
                                        <span class="badge bg-success" th:text="'评分: ' + ${movie.score}"></span>
                                    </p>
                                    <p class="card-text small text-muted" th:text="${#dates.format(movie.releaseDate, 'yyyy-MM-dd')}"></p>
                                </div>
                                <div class="card-footer bg-transparent">
                                    <small class="text-muted" th:text="'播放: ' + ${movie.playCount}"></small>
                                </div>
                            </div>
                        </div>
                    </div>

                    <!-- 分页 -->
                    <nav class="mt-4" th:if="${pageCount > 1}">
                        <ul class="pagination justify-content-center">
                            <li class="page-item" th:classappend="${currentPage == 1 ? 'disabled' : ''}">
                                <a class="page-link" th:href="@{'/movie/' + ${type} + '/' + ${creator.id} + '?pageNo=' + ${currentPage - 1}}">上一页</a>
                            </li>
                            <li class="page-item" th:each="i : ${#numbers.sequence(1, pageCount)}" th:classappend="${i == currentPage ? 'active' : ''}">
                                <a class="page-link" th:href="@{'/movie/' + ${type} + '/' + ${creator.id} + '?pageNo=' + ${i}}" th:text="${i}"></a>
                            </li>
                            <li class="page-item" th:classappend="${currentPage == pageCount ? 'disabled' : ''}">
                                <a class="page-link" th:href="@{'/movie/' + ${type} + '/' + ${creator.id} + '?pageNo=' + ${currentPage + 1}}">下一页</a>
                            </li>
                        </ul>
                    </nav>
                </div>
            </div>
        </div>

        <div class="col-md-4">
            <!-- 相关推荐 -->
            <div class="card">
                <div class="card-header">相关推荐</div>
                <div class="list-group list-group-flush">
                    <a th:each="m : ${recommendations}" th:href="@{'/movie/' + ${m.id}}"
                       class="list-group-item list-group-item-action d-flex justify-content-between align-items-center">
                        <div>
                            <h6 class="mb-1" th:text="${m.name}"></h6>
                            <small class="text-muted">
                                <span th:each="category : ${m.categories}" class="badge bg-primary me-1" th:text="${category.name}"></span>
                                <span class="mx-1">|</span>
                                <span th:text="'评分: ' + ${m.score}"></span>
                            </small>
                        </div>
                        <span class="badge bg-primary rounded-pill" th:text="${m.playCount}"></span>
                    </a>
                </div>
            </div>
        </div>
    </div>
</div>

<script src="/js/jquery.min.js"></script>
<script src="/js/bootstrap.bundle.min.js"></script>
</body>
</html>